<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" href="skin/base.css" type="text/css"  />
<link rel="stylesheet" href="skin/user.css" type="text/css" >
<link rel="stylesheet" href="skin/btn.css" type="text/css" />
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body ontouchstart>
<div id="main">
  <div class="user">
    <div class="user_my_head" onclick="user_bg();" id="user_bg">
      <div class="avatar" id="avatar"></div>
      <div class="nk" id='nk' onclick="oauth('login');">登录</div>
      
   
    </div>
    <ul class="user_my_menu">
      <li ontouchstart="zy_touch('down')" onclick="talk()">我的说说<span id='talk'>0</span></li>
      <li ontouchstart="zy_touch('down')" onclick="oauth('user_coupons')">我的优惠券<span id='coupons'>0</span></li>
      <li ontouchstart="zy_touch('down')" onclick="oauth('user_activity')">我的活动<span id='activity'>0</span></li>
      
      <!--
	  <li ontouchstart="zy_touch('down')"  onclick="oauth('user')">我的阅读</li>
      <li ontouchstart="zy_touch('down')"  onclick="oauth('user')">我喜欢的商家</li>
	  -->
    </ul>
  </div>
</div>
</body>
<script>
    zy_init();
	function user_avatar(){
		if (!c_l()) {
			gologin();
			return false;
		}

		uexImageBrowser.pick();
		uexImageBrowser.cbPick= function (opCode,dataType,data){
			if(dataType==0){
				var photos =data;
				if(photos==''){
					return false;
				}
				var url = app_path+'index.php?m=iapp&c=user&a=avatar&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
				
				uexXmlHttpMgr.open(99,'post',url,"12000");
				uexXmlHttpMgr.setPostData(99,'1','avatardata',photos);
				uexXmlHttpMgr.send(99);
				uexWindow.toast(1, 5, '头像修改中，请稍候~', 0);
			}
		}
	}
	
	
	
	function user_bg(){
		if (!c_l()) {
			gologin();
			return false;
		}
		uexWindow.cbActionSheet = function(opId,dataType,data){
			if(dataType==2){
				if(data==0){
					uexImageBrowser.pick();
					uexImageBrowser.cbPick= function (opCode,dataType,data){
						if(dataType==0){
							var photos =data;
							if(photos==''){
								return false;
							}
							var url = app_path+'index.php?m=iapp&c=user&a=set_user_bg&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
							uexXmlHttpMgr.open(2,'post',url,"12000");
							uexXmlHttpMgr.setPostData(2,'1','photos',photos);
							uexXmlHttpMgr.send(2);
							uexWindow.toast(1, 5, '背景更换中，请稍候~', 0);
						}
					}
				}else if(data==1){
					var url = app_path+'index.php?m=iapp&c=user&a=del_user_bg&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
					uexXmlHttpMgr.open(3,'post',url,"5000");
					uexXmlHttpMgr.send(3);
					uexWindow.toast(1, 5, '默认背景恢复中，请稍候~', 0);
				}
			}
		}
		uexWindow.actionSheet('可以换个性化背景哦？','取消',['更换背景','恢复默认背景']);
	}
	
	
	function oauth(windowname){
		if (!c_l()) {
			gologin();
			return false;
		}
		uexWindow.open(windowname, '0', windowname+'.html', 2, '', '', 0);
	}
	
	function talk(){
		localStorage['userid'] = localStorage['u_id'];
		localStorage['user_home_nickname'] = localStorage['u_nick'];
		uexWindow.open('user_talk', '0', 'user_talk.html', 2, '', '', 0);
	}
	
	function login(){
		localStorage['login'] = 'more';
		openWin('login', 'login.html', '12');
	}
	
	function oklogin(){
		if(Users.checkUser()){
			$$('nk').innerHTML=localStorage['u_nick'];
			$$('button').innerHTML='<li onclick="logout()">退出登录</li> <li onclick="oauth(\'user_info\')">我的资料</li>';	
			
			var url = app_path+'index.php?m=iapp&c=user&a=my_info&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
			uexXmlHttpMgr.open(1,'post',url,"8000");
			uexXmlHttpMgr.send(1);
		
		}else{
			$$('button').innerHTML='<li onclick="oauth(\'login\')">用户登录</li>';
			$$('avatar').innerHTML = '';
			$$('nk').innerHTML = '';
		}
	}
	
	function lout(){
		uexWindow.cbActionSheet = function(opId,dataType,data){
			if(dataType==2){
				if(data==0){
					logout();
					oklogin();
					oklogin("退出成功~");
				}
			}
		}
		uexWindow.actionSheet('你确定要退出登录吗？','取消',['退出登录']);
　　	}
	
	window.uexOnload = function(type){
		if (!type) {
			uexWindow.setBounce("1");
			uexWindow.showBounceView("0","#666","0");
			uexWindow.showBounceView("1","#666","0");
			uexXmlHttpMgr.onData = function(opId, status, data){
				uexXmlHttpMgr.close(opId);
				uexWindow.closeToast();
				if (status == 1) {
					data = JSON.parse(data);
					if(opId ==1){
						if(data['success'] == 'OK'){
							if(data['data']['avatar']!=''){
								$$('avatar').innerHTML = '<img src="' + data['data']['avatar'] + '" />';
							}
							if (data['data']['bg'] != '') {
								$$('user_bg').style.backgroundImage = 'url('+data['data']['bg']+')';
							}
							
							if (data['data']['praise'] != '') {
								$$('user_praise').innerHTML = data['data']['praise'];
							}
							
							$$('nk').innerHTML = data['data']['nickname'];
							$$('talk').innerHTML = data['data']['talk'];
							$$('coupons').innerHTML = data['data']['coupons'];
							$$('activity').innerHTML = data['data']['activity'];
						}else{
							uexWindow.toast("0", "5", '请求个人资料失败', 1000);
						}
					}else if (opId == 2) {
							if(data['success'] == 'OK'){
								$$('user_bg').style.backgroundImage= 'url('+data['data']['bg']+')';
								uexWindow.toast("0", "5", '背景修改成功~', 1000);
							}else{
								uexWindow.toast("0", "5", '背景修改失败~', 1000);
							}
					}else if (opId == 3) {
							if(data['success'] == 'OK'){
								$$('user_bg').style.backgroundImage= 'url(skin/images/user/user_head_bg.jpg)';
								uexWindow.toast("0", "5", data['msg'], 1000);
							}else{
								uexWindow.toast("0", "5", data['msg'], 1000);
							}
					}else if (opId == 99) {
							uexWindow.closeToast();
							if(data['success'] == 'OK'){
								$$('avatar').innerHTML = '<img src="' + data['data']['avatar'] + '" />';
								uexWindow.toast("0", "5", '头像修改成功~', 1000);
							}else{
								uexWindow.toast("0", "5", '头像修改失败~', 1000);
							}
					}
				}else if(status ==-1){
					uexWindow.toast("0", "5", '提交超时', 1000);
				}
			}
			oklogin();
		}
	}
	
</script>
</html>